/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 *
 * @author: jin Chen 
 * @date: Aug 26, 2003$
 * @version: 1.0
 */
package edu.psu.geovista.app.pcp.toolkits;

import java.util.Calendar;

public abstract class SlowEventSender {
    protected  long interval;

    protected  long lastSendTime=0;
    protected  long currTime=0;
    protected  boolean isToSend;

    public SlowEventSender() {
    }

    public SlowEventSender(long interval) {
        this.interval = interval;
    }

    public void send(Object para) {
        currTime=Calendar.getInstance().getTimeInMillis() ;
        if(lastSendTime==0){
            doTask(para);
            this.lastSendTime =currTime;
        }
        else{
            if(currTime-lastSendTime>=this.interval ){
                doTask(para);
                this.lastSendTime =currTime;
            }
            //isToSend=false;
        }
    }

    protected  abstract void doTask(Object para);/*{if(isToSend) doTask();}*/

    public void setInterval(long interval) {
        this.interval = interval;
    }
}
